#!/usr/bin/python3
# -*- coding: utf-8 -*-

'''
素数：只能被1和它本身整除，这样的数称之为素数 

while 1:
	a = input('请输入一个整数：');
	if a.isdigit():
		a = eval(a);
		for i in range(2,a):
			if a % i == 0:
				print(a,'不是素数');
				break;
		else:
			print(a,'是素数');
	else:
		print('不是数字');
'''

'''
求两个正整数m和n的最大公约数：
def hcf(x, y):
	t = min(x, y);
	g = 1;
	for i in range(1,int(t/2)):
		if x%i==0 and y%i==0:
			g=i;
	else:
		return g;

a = hcf(11, 20);
print(a);
'''

'''
N个人围城一桌（首位相连），约定从1报数，报到数为a的人出局，
然后下一位又从1开始报，以此类推。最后留下的人获胜。

def getWin(n,a):
	dict = {x:x for x in range(n)}
	length = len(dict)
	j = 1 #计数
	while (length>1):
		for k in list(dict.keys()):
			if j == a:
				dict.pop(k)
				length -= 1
				j = 0
			j += 1
	return dict

n = 100000
m = 100000
s = 0

for i in range(2,n):
	print(s,'+',m,'%',i,'=',end=" ")
	s = (s + m) % i
	print(s)
'''

'''
ax*x + bx + c = 0

import math

def quadratic(a, b, c):
	v = b*b-4*a*c
	if v >= 0:
		x1 = (-b + math.sqrt(v))/(2*a)
		x2 = (-b - math.sqrt(v))/(2*a)
		return x1,x2
	else:
		return TypeError('无解')
ret = quadratic(1,1,1)
print(ret)

'''

'''
汉诺塔问题
def move(n, a='A', b='B', c='C'):
	if n == 1:
		print(a, c)
	else:
		move((n-1), a, c, b)
		print(a, c)
		move((n-1), b, a, c)
move(4)
'''


# 利用字符串切片去字符串两边空格
'''
def trim(s):
    if s[0] == ' ':
        return trim(s[1:])
    elif s[-1] == ' ':
        return trim(s[0:-1])
    else:
        return s

s = '    aghs dfgsdg    '
print(trim(s))
'''
'''
找最大最小值
L = [2,1,5,3,4]
def findMinAndMax(L):
	min = max = L[0]
	for i in L:
		if i >= max:
			max = i
		if i <= min:
			min = i
	return min, max
print(findMinAndMax(L))
'''

'''
生成器 -- 杨辉三角(升级版)

def triangles():
	list1 = []
	s = 0
	
	while True:
		if s == 0 or s == len(list1)-1:
			list1.append([1])

		elif s == 1:
			list1.append([1,1])

		else:
			list2 = []
			i = 0

			while i <= s:
				if i == 0 or i==s:
					list2.append(1)
				else:
					list2.append(list1[s-1][i-1]+list1[s-1][i])
				i += 1
				
			list1.append(list2)

		print(list1[s])
		yield list1
		s += 1

t = triangles()
next(t)
next(t)
next(t)
next(t)
next(t)
'''

'''
# 利用map()函数，把用户输入的不规范的英文名字，变为首字母大写，其他小写的规范名字。
# 输入：['adam', 'LISA', 'barT']，输出：['Adam', 'Lisa', 'Bart']：
def normalize(name):
	return name.lower().capitalize()

L1 = ['adam', 'LISA', 'barT']
L2 = list(map(normalize, L1))
print(L2)

# Python提供的sum()函数可以接受一个list并求和，请编写一个prod()函数，
# 可以接受一个list并利用reduce()求积：
from functools import reduce

def prod(L):
	return reduce(lambda x, y: x * y, L)
print(prod([1,2,3, 4]))

# 利用map和reduce编写一个str2float函数，把字符串'123.456'转换成浮点数123.456：
def fi(x, y):
	return x * 10 + y
def ff(x, y):
	return x / 10 + y
def char2num(s):
	digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
	return digits[s]
def str2float(S):
	l = S.split('.')
	l[1] = l[1][::-1]
	zh = reduce(fi, map(char2num, l[0]))
	xi = reduce(ff,  map(char2num, l[1])) / 10
	return zh+xi

print(str2float('123.456'))
'''

'''
回数是指从左向右读和从右向左读都是一样的数，例如12321，909。请利用filter()筛选出回数：

def is_palindrome(n):
    if n < 10 and n > 0:
    	return True
    else:
    	s = str(n)
    	return s == s[::-1]

print(list(filter(is_palindrome, range(1,10000))))
'''

'''
假设我们用一组tuple表示学生名字和成绩：

L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

请用sorted()对上述列表分别按名字排序：

def by_name(t):
	x, y = t
	return x.lower()

再按成绩从高到低排序：

def by_score(t):
	x, y = t
	return -y
print(sorted(L,key=by_score))
'''
'''
import sys
 
print('命令行参数如下:')
for i in sys.argv:
   print(i)
 
print('\n\nPython 路径为：', sys.path, '\n')

import hello
print(hello)
print(hello.test())
print(hello.greeting('namename'))
print(hello._private_2('dfhgdf456'))
'''

'''
x = int(input("please enter first integer:"))
y = int(input("please enter second integer:"))

# 一般的写法
if (x == y):
    print("两数相同！")
elif (x > y):
    print("较大的数为：", x)
else:
    print("较大的数为：", y)

# 三目运算符写法
print('aa' if (x > y) else 'bb')
'''

'''
# 找到字符串的位置分布
def find_str_position(m_str, c_str):
    mlen = len(m_str)
    clen = len(c_str)
    position_list = []

    for i in range(mlen):
        if i+clen <= mlen:
            tmp_str = ''
            for j in range(clen):
                tmp_str += m_str[i+j]

            if tmp_str == c_str:
                position_list.append(i)

    return position_list

print(find_str_position('aabbcc', 'bb'))
'''

'''
str = 'abcde'
print(str[::-1])
print(str[0:2:1])
print(str[-1:-3:-1])
print(str[-1])
'''

# 得到字符串里面的数字
def find_str_num(m_str):
    n_str = ''
    for i in m_str:
        if i.isdecimal():
            n_str += i
    return n_str

print(find_str_num('第56话'))
print(find_str_num('vol_03'))

print(type(1))
print(type(int('1')))